import java.util.*;

public class JIdeaPool {

	private Map<JTopic, Set<JIdea>> pool;
	
	public JIdeaPool(){
		pool = new HashMap<JTopic, Set<JIdea>>();
	}
	
	public void add(JTopic topic){
		if(topic==null)
			throw new NullPointerException();
		if(pool.containsKey(topic)==true)
			return;
		pool.put(topic,null);
	}
	
	public void add(JIdea idea, JTopic topic){
		if(topic==null)
			throw new NullPointerException();
		if(pool.containsKey(topic)==false){
			Set<JIdea> temp = new HashSet<JIdea>();
			temp.add(idea);
			pool.put(topic, temp);
		}
		else{
			Set<JIdea> temp = pool.get(topic);
			if(temp.contains(idea)==true)
				return;
			temp.add(idea);
			pool.put(topic, temp);
		}
	}
	
	public boolean remove(JIdea idea){
		if(idea ==null)
			throw new NullPointerException();
		if(pool.containsValue(idea)==false)
			return false;
		for(JTopic temp : pool.keySet()){
			Set<JIdea> values = pool.get(temp);
			if(values.contains(idea)==true){
				values.remove(idea);
				pool.put(temp, values);
				return true;
			}
		}
		return false;
	}
	
	public boolean remove(JTopic topic){
		 if(topic==null)
			 throw new NullPointerException();
		 if(pool.containsKey(topic)==false)
			 return false;
		 pool.remove(topic);
		 return true;
	}
	
	public int numberOfTopics(){
		return pool.size();
	}
	
	public int numberOfIdeas(){
		Set<JIdea> ideas = new HashSet<JIdea>();
		for(JTopic temp : pool.keySet()){
			Set<JIdea> tempidea = pool.get(temp);
			ideas.addAll(tempidea);
		}
		return ideas.size();
	}
	
}
